<?php
namespace App\TxSchool\Type;

use App\TxSchool\Exceptions\ParamRequiredException;

/**
 * Class ThirdParty
 * @package App\TeSchool\Type
 * 第三方应用模式
 */
class App extends Type {
    /**
     * App constructor.
     * @param array $params
     * @throws ParamRequiredException
     */
    public function __construct(array $params)
    {
        $this->checkParams($params);
        $this->set('objectid',$params['objectid']);
        $this->set('objType',$params['objType']);
        $this->set("openAppID",$params['openAppID']);
        $this->key = $params['openAppSecret'];
    }

    /**
     * @param array $params
     * @throws ParamRequiredException
     */
    private function checkParams(array $params){
        if(!isset($params['objectid'])){
            throw new ParamRequiredException("objectid");
        }
        if(!isset($params['objType'])){
            throw new ParamRequiredException("objType");
        }
        if(!isset($params['openAppID'])){
            throw new ParamRequiredException("openAppID");
        }
        if(!isset($params['openAppSecret'])){
            throw new ParamRequiredException("openAppSecret");
        }
    }
}
